*************************************************************************************
* This file creates the coupon data necessary for the yield-to-maturity calculation *
*************************************************************************************


   



   
   
  
  *** Load bond data and exchange rates 

		*** load transcribed data from excel files and save as stata format
		{
		
			
			* Exchange rates and Dawes bond price data
			import excel "$Replicationdirectory/_Data/Dawes Bond and exchange rates/Dawes_data.xlsx",   firstrow case(lower) clear
			
			save "$Replicationdirectory/_Work/TEMP/Dawesraw",  replace 
			
			** Other 
			
				* Value of Dawes Mark in terms of Reichsmark (needed for calculation of GBP-equivalent of  non-GBP coupon payment)
				 {
		
		
					** load exchange rates of Registermark for non-cash payments

						import excel "$Replicationdirectory/_Data/Sperrmark Exchange Rates/Sperrmarks_data.xlsx", sheet("Data")  clear first
					 
								tsset date
								keep if tin(1jan1935,31aug1939)

				 
				 
						* convert to exchange rate (data is recorded as discount vis-a-vis official Reichsmark)
							 
							replace Register=100-Register
							
						
						* extrapolate with last available value 
							gen Register_lastavail=Register
							replace Register_lastavail=Register_lastavail[_n-1]  if Register>=. 
							replace Register=Register_lastavail
							drop Register_lastavail
							
							label var Register "Value of Registermark relative to official RM value (in %)"

							rename Register RateRegisterRM 
							
							save 	 "$Replicationdirectory/_Work/TEMP/DMRMrate" , replace

		}
	
 	
		
		}
		
		
		
		
		
		*** define/add time variables/tradingdays/default definitions
		{ 	
								use "$Replicationdirectory/_Work/TEMP/Dawesraw"
									

								
								tsset date, daily
								
								* quarter and year var
								gen quarter = quarter(dofd(date))
								gen year = year(dofd(date))
								egen quarter_cont_count=group(quarter year)
								
								gen month=month(date)
					

								* add a counter for weeks 
									gen week=0
									
									gen day_in_sample=_n
									
									replace day_in_sample=day_in_sample+3
									 
									replace week=week+floor(day_in_sample/7)
									replace week=week-1560
 
 
								*create dummy for default
											gen default=1 if date>td(14jun1934)
											replace default=0 if default==.
											
											label var default "Germany in default (from June 14, 1934) onwards"
							

								* code tradingdays  
												gen tradingday_london=1 if weekday_n<=5 & date!=td(01jan1930) & date!=td(18apr1930) & date!=td(20apr1930) & date!=td(21apr1930) & date!=td(08jun1930) & date!=td(09jun1930) & date!=td(25dec1930) & date!=td(26dec1930) & date!=td(01jan1931) & date!=td(03apr1931) & date!=td(05apr1931) & date!=td(06apr1931) & date!=td(24may1931) & date!=td(25may1931) & date!=td(22sep1931) & date!=td(25dec1931) & date!=td(26dec1931) & date!=td(27dec1931) & date!=td(01jan1932) & date!=td(25mar1932) & date!=td(27mar1932) & date!=td(28mar1932) & date!=td(15may1932) & date!=td(16may1932) & date!=td(25dec1932) & date!=td(26dec1932) & date!=td(01jan1933) & date!=td(14apr1933) & date!=td(16apr1933) & date!=td(17apr1933) & date!=td(04jun1933) & date!=td(05jun1933) & date!=td(24dec1933) & date!=td(25dec1933) & date!=td(26dec1933) & date!=td(01jan1934) & date!=td(30mar1934) & date!=td(01apr1934) & date!=td(02apr1934) & date!=td(20may1934) & date!=td(21may1934) & date!=td(25dec1934) & date!=td(26dec1934) & date!=td(01jan1935) & date!=td(19apr1935) & date!=td(21apr1935) & date!=td(22apr1935) & date!=td(09jun1935) & date!=td(10jun1935) & date!=td(25dec1935) & date!=td(26dec1935) & date!=td(01jan1936) & date!=td(10apr1936) & date!=td(12apr1936) & date!=td(13apr1936) & date!=td(31may1936) & date!=td(01jun1936) & date!=td(25dec1936) & date!=td(26dec1936) & date!=td(27dec1936) & date!=td(01jan1937) & date!=td(26mar1937) & date!=td(28mar1937) & date!=td(29mar1937) & date!=td(16may1937) & date!=td(17may1937) & date!=td(25dec1937) & date!=td(26dec1937) & date!=td(01jan1938) & date!=td(15apr1938) & date!=td(17apr1938) & date!=td(18apr1938) & date!=td(05jun1938) & date!=td(06jun1938) & date!=td(25dec1938) & date!=td(26dec1938) & date!=td(01jan1939) & date!=td(07apr1939) & date!=td(09apr1939) & date!=td(10apr1939) & date!=td(28may1939) & date!=td(29may1939) & date!=td(04aug1930) & date!=td(03aug1931) & date!=td(01aug1932) & date!=td(27dec1932) & date!=td(07aug1933) & date!=td(06aug1934) & date!=td(06may1935) & date!=td(05aug1935) & date!=td(21jan1936) & date!=td(28jan1936) & date!=td(03aug1936) & date!=td(02aug1937) & date!=td(27dec1937) & date!=td(01aug1938) & date!=td(27dec1938)  

												replace tradingday_london=1 if weekday_n==6 & date>=td(19sep1931) & date<=td(26may1934)

												gen tradingday_paris=1 if weekday_n<=6 & date!=td(01jan1930) & date!=td(18apr1930) & date!=td(20apr1930) & date!=td(21apr1930) & date!=td(08jun1930) & date!=td(09jun1930) & date!=td(25dec1930) & date!=td(26dec1930) & date!=td(01jan1931) & date!=td(03apr1931) & date!=td(05apr1931) & date!=td(06apr1931) & date!=td(24may1931) & date!=td(25may1931) & date!=td(22sep1931) & date!=td(25dec1931) & date!=td(26dec1931) & date!=td(27dec1931) & date!=td(01jan1932) & date!=td(25mar1932) & date!=td(27mar1932) & date!=td(28mar1932) & date!=td(15may1932) & date!=td(16may1932) & date!=td(25dec1932) & date!=td(26dec1932) & date!=td(01jan1933) & date!=td(14apr1933) & date!=td(16apr1933) & date!=td(17apr1933) & date!=td(04jun1933) & date!=td(05jun1933) & date!=td(24dec1933) & date!=td(25dec1933) & date!=td(01jan1934) & date!=td(30mar1934) & date!=td(01apr1934) & date!=td(02apr1934) & date!=td(20may1934) & date!=td(21may1934) & date!=td(25dec1934) & date!=td(01jan1935) & date!=td(19apr1935) & date!=td(21apr1935) & date!=td(22apr1935) & date!=td(09jun1935) & date!=td(10jun1935) & date!=td(25dec1935) & date!=td(01jan1936) & date!=td(10apr1936) & date!=td(12apr1936) & date!=td(13apr1936) & date!=td(31may1936) & date!=td(01jun1936) & date!=td(25dec1936) & date!=td(26dec1936) & date!=td(27dec1936) & date!=td(01jan1937) & date!=td(26mar1937) & date!=td(28mar1937) & date!=td(29mar1937) & date!=td(16may1937) & date!=td(17may1937) & date!=td(25dec1937) & date!=td(26dec1937) & date!=td(01jan1938) & date!=td(15apr1938) & date!=td(17apr1938) & date!=td(18apr1938) & date!=td(05jun1938) & date!=td(06jun1938) & date!=td(25dec1938) & date!=td(26dec1938) & date!=td(01jan1939) & date!=td(07apr1939) & date!=td(09apr1939) & date!=td(10apr1939) & date!=td(28may1939) & date!=td(29may1939) & date!=td(29may1930) & date!=td(14jul1930) & date!=td(15aug1930) & date!=td(01nov1930) & date!=td(11nov1930) & date!=td(14may1931) & date!=td(14jul1931) & date!=td(15aug1931) & date!=td(01nov1931) & date!=td(11nov1931) & date!=td(05may1932) & date!=td(14jul1932) & date!=td(15aug1932) & date!=td(01nov1932) & date!=td(11nov1932) & date!=td(25may1933) & date!=td(14jul1933) & date!=td(15aug1933) & date!=td(01nov1933) & date!=td(11nov1933) & date!=td(10may1934) & date!=td(14jul1934) & date!=td(15aug1934) & date!=td(01nov1934) & date!=td(11nov1934) & date!=td(30may1935) & date!=td(14jul1935) & date!=td(15aug1935) & date!=td(01nov1935) & date!=td(11nov1935) & date!=td(21may1936) & date!=td(14jul1936) & date!=td(15aug1936) & date!=td(28sep1936) & date!=td(29sep1936) & date!=td(01nov1936) & date!=td(11nov1936)& date!=td(06may1937) & date!=td(14jul1937) & date!=td(15aug1937) & date!=td(29jun1937) & date!=td(30jun1937) & date!=td(01nov1937) & date!=td(11nov1937)& date!=td(26may1938) & date!=td(14jul1938) & date!=td(15aug1938) & date!=td(01nov1938) & date!=td(11nov1938)& date!=td(18may1939) & date!=td(14jul1939)

												gen tradingday_amsterdam=1 if weekday_n<=6 & date!=td(01jan1930) & date!=td(18apr1930) & date!=td(20apr1930) & date!=td(21apr1930) & date!=td(08jun1930) & date!=td(09jun1930) & date!=td(25dec1930) & date!=td(26dec1930) & date!=td(01jan1931) & date!=td(03apr1931) & date!=td(05apr1931) & date!=td(06apr1931) & date!=td(24may1931) & date!=td(25may1931) & date!=td(22sep1931) & date!=td(25dec1931) & date!=td(26dec1931) & date!=td(27dec1931) & date!=td(01jan1932) & date!=td(25mar1932) & date!=td(27mar1932) & date!=td(28mar1932) & date!=td(15may1932) & date!=td(16may1932) & date!=td(25dec1932) & date!=td(26dec1932) & date!=td(01jan1933) & date!=td(14apr1933) & date!=td(16apr1933) & date!=td(17apr1933) & date!=td(04jun1933) & date!=td(05jun1933) & date!=td(24dec1933) & date!=td(25dec1933) & date!=td(26dec1933) & date!=td(01jan1934) & date!=td(30mar1934) & date!=td(01apr1934) & date!=td(02apr1934) & date!=td(20may1934) & date!=td(21may1934) & date!=td(25dec1934) & date!=td(26dec1934) & date!=td(01jan1935) & date!=td(19apr1935) & date!=td(21apr1935) & date!=td(22apr1935) & date!=td(09jun1935) & date!=td(10jun1935) & date!=td(25dec1935) & date!=td(26dec1935) & date!=td(01jan1936) & date!=td(10apr1936) & date!=td(12apr1936) & date!=td(13apr1936) & date!=td(31may1936) & date!=td(01jun1936) & date!=td(25dec1936) & date!=td(26dec1936) & date!=td(27dec1936) & date!=td(01jan1937) & date!=td(26mar1937) & date!=td(28mar1937) & date!=td(29mar1937) & date!=td(16may1937) & date!=td(17may1937) & date!=td(25dec1937) & date!=td(26dec1937) & date!=td(01jan1938) & date!=td(15apr1938) & date!=td(17apr1938) & date!=td(18apr1938) & date!=td(05jun1938) & date!=td(06jun1938) & date!=td(25dec1938) & date!=td(26dec1938) & date!=td(01jan1939) & date!=td(07apr1939) & date!=td(09apr1939) & date!=td(10apr1939) & date!=td(28may1939) & date!=td(29may1939) & date!=td(29may1930) & date!=td(31aug1930) & date!=td(14may1931) & date!=td(31aug1931) & date!=td(05may1932) & date!=td(31aug1932) & date!=td(25may1933) & date!=td(31aug1933) & date!=td(10may1934) & date!=td(31aug1934) & date!=td(30may1935) & date!=td(31aug1935) & date!=td(21may1936) & date!=td(28sep1936) & date!=td(31aug1936) & date!=td(06may1937) & date!=td(31aug1937) & date!=td(26may1938) & date!=td(31aug1938) & date!=td(18may1939)

												gen tradingday_zurich=1 if weekday_n<=6 & date!=td(01jan1930) & date!=td(18apr1930) & date!=td(20apr1930) & date!=td(21apr1930) & date!=td(08jun1930) & date!=td(09jun1930) & date!=td(25dec1930) & date!=td(26dec1930) & date!=td(01jan1931) & date!=td(03apr1931) & date!=td(05apr1931) & date!=td(06apr1931) & date!=td(24may1931) & date!=td(25may1931) & date!=td(22sep1931) & date!=td(25dec1931) & date!=td(26dec1931) & date!=td(27dec1931) & date!=td(01jan1932) & date!=td(25mar1932) & date!=td(27mar1932) & date!=td(28mar1932) & date!=td(15may1932) & date!=td(16may1932) & date!=td(25dec1932) & date!=td(26dec1932) & date!=td(01jan1933) & date!=td(14apr1933) & date!=td(16apr1933) & date!=td(17apr1933) & date!=td(04jun1933) & date!=td(05jun1933) & date!=td(24dec1933) & date!=td(25dec1933) & date!=td(26dec1933) & date!=td(01jan1934) & date!=td(30mar1934) & date!=td(01apr1934) & date!=td(02apr1934) & date!=td(20may1934) & date!=td(21may1934) & date!=td(25dec1934) & date!=td(26dec1934) & date!=td(01jan1935) & date!=td(19apr1935) & date!=td(21apr1935) & date!=td(22apr1935) & date!=td(09jun1935) & date!=td(10jun1935) & date!=td(25dec1935) & date!=td(26dec1935) & date!=td(01jan1936) & date!=td(10apr1936) & date!=td(12apr1936) & date!=td(13apr1936) & date!=td(31may1936) & date!=td(01jun1936) & date!=td(25dec1936) & date!=td(26dec1936) & date!=td(27dec1936) & date!=td(01jan1937) & date!=td(26mar1937) & date!=td(28mar1937) & date!=td(29mar1937) & date!=td(16may1937) & date!=td(17may1937) & date!=td(25dec1937) & date!=td(26dec1937) & date!=td(01jan1938) & date!=td(15apr1938) & date!=td(17apr1938) & date!=td(18apr1938) & date!=td(05jun1938) & date!=td(06jun1938) & date!=td(25dec1938) & date!=td(26dec1938) & date!=td(01jan1939) & date!=td(07apr1939) & date!=td(09apr1939) & date!=td(10apr1939) & date!=td(28may1939) & date!=td(29may1939) & date!=td(02jan1930) & date!=td(19apr1930) & date!=td(29may1930) & date!=td(01aug1930)& date!=td(02jan1931) & date!=td(04apr1931) & date!=td(14may1931) & date!=td(01aug1931)& date!=td(02jan1932) & date!=td(26mar1932) & date!=td(05may1932) & date!=td(01aug1932)& date!=td(02jan1933) & date!=td(15apr1933) & date!=td(25may1933) & date!=td(01aug1933)& date!=td(02jan1934) & date!=td(31mar1934) & date!=td(10may1934) & date!=td(01aug1934)& date!=td(02jan1935) & date!=td(20apr1935) & date!=td(30may1935) & date!=td(01aug1935)& date!=td(02jan1936) & date!=td(11apr1936) & date!=td(21may1936) & date!=td(28sep1936) & date!=td(01aug1936)& date!=td(02jan1937) & date!=td(27mar1937) & date!=td(06may1937) & date!=td(01aug1937)& date!=td(02jan1938) & date!=td(16apr1938) & date!=td(26may1938) & date!=td(01aug1938)& date!=td(02jan1939) & date!=td(08apr1939) & date!=td(18may1939)

												
												* label and calculate sums 
												foreach market of global markets{
												
													* Overall
													label var tradingday_`market' "Trading day (1/0) in `market'"
													egen N_tradingdays_`market'=sum(tradingday_`market')
													label var N_tradingdays_`market' "Total N of trading days in `market'"
													
													* Pre-default N_market days
													egen N_tradingdays_`market'_pre=sum(tradingday_`market') if default==0
													label var N_tradingdays_`market'_pre "Total N of trading days in `market' pre-default"

													
 													* Post-default N_market days
													egen N_tradingdays_`market'_post=sum(tradingday_`market') if default==1
													label var N_tradingdays_`market'_post "Total N of trading days in `market' post-default"

 												}
										  		}
							
										

										
					

		
		
		
		
		

		*** label data  & convert into GBP
		{

								* Spot market rates
								label var spotm_fr 	"Spot market exchange rate French Franc/GBP"
								label var spotm_ch 	"Spot market exchange rate Swiss Franc/GBP"
								label var spotm_usa "Spot market exchange rate US Dollar/GBP"
								label var spotm_nl	"Spot market exchange rate Florin/GBP"
								
								
								* Bonds
								
									* Original data (as in listing) 
									rename lon P_london_GBP_GBP 
										label var P_london_GBP_GBP "Price of GBP Dawes Bond in London (in pounds)"

									rename par_or P_paris_GBP_FFranc 
										label var P_paris_GBP_FFranc "Price of Dawes Bond in Paris in French Franc"

									rename am_or P_amsterdam_GBP_Florin 
										label var  P_amsterdam_GBP_Florin "Price of Dawes Bond in Amsterdam in Gulden at % of Sterling rate"
										
												* In Amsterdam, bonds with and without affidavit were traded // We use those with affidavit  when it becomes available (October 15, 1934)  
												replace P_amsterdam_GBP_Florin=am_ket_or if date>=td(15oct1934)

											
 									rename zu_gbp_or P_zurich_GBP_CHF 
										label var P_zurich_GBP_CHF "Price of Dawes Bond in British Pounds (trade in GBP there)"
 
									rename zu_chf  P_zurich_CHF_CHF
										label var P_zurich_CHF_CHF "Price of Dawes Bond in CHF in Zurich at % of Sterling rate"
										
										
						
													
								
								
											* convert price series into GBP (see appendix for description


											gen P_paris_GBP_GBP=P_paris_GBP_FFranc/spotm_fr/100

											gen P_amsterdam_GBP_GBP=P_amsterdam_GBP_Florin*12/spotm_nl

											gen P_zurich_GBP_GBP=P_zurich_GBP_CHF*25.25/spotm_ch
											
											
											label var P_london_GBP_GBP 		"London"
											label var P_paris_GBP_GBP 		"Paris"
											label var P_amsterdam_GBP_GBP 	"Amsterdam"
											label var P_zurich_GBP_GBP 		"Zurich"
									 
											
																		
											* rename  variables (LCU= Local currency unit)
											rename P_paris_GBP_FFranc  			P_paris_LCU
											rename P_amsterdam_GBP_Florin 		P_amsterdam_LCU
											rename P_zurich_GBP_CHF				P_zurich_LCU
 									
								 
			}					 
								
								
 		
					
		
		
		*** Coupon data
		{
		
								
								
									
										*facevalue
										gen facevalue=100
										
										* coupon payment for different markets
										
										
															* London
															gen annual_coupon_cash_london=7 if tin(1jan1930,30jun1938)
															gen annual_coupon_noncash_london=0
															
																* change in 1938
																replace annual_coupon_cash_london=5 if tin(1jul1938,1jul1940)
															
															* coupon changes in Paris
															gen annual_coupon_cash_paris=7 if tin(1jan1930,30jun1938)
															gen annual_coupon_noncash_paris=0

																* change in 1938
																replace annual_coupon_cash_paris=5 if tin(1jul1938,1jul1940)
																
															
															 

															***** Netherlands ****
															
															gen annual_coupon_cash_amsterdam=7 	if tin(1jan1930,13jun1935)
															gen annual_coupon_noncash_amsterdam=0	if tin(1jan1930,13jun1935)

															
																*Change 1935: 3.5% cash + 3.5% in Registermark
																replace annual_coupon_cash_amsterdam=3.5 if tin(14jun1935,1jul1940)
																replace annual_coupon_noncash_amsterdam=3.5	if tin(14jun1935,31may1937)
				

																*Change in 1938: 3.5% cash + 2% in Registermark
																replace annual_coupon_noncash_amsterdam=2 if tin(1jun1937,1jul1940)																		
															 
															 
															  
																					
															***** Zurich ****  
															
															gen annual_coupon_cash_zurich=7 if tin(1jan1930,16apr1935)
															gen annual_coupon_noncash_zurich=0 if tin(1jan1930,16apr1935)

																* change in 1935 
																replace annual_coupon_cash_zurich=4.5 if tin(17apr1935,1jul1940)
																replace annual_coupon_noncash_zurich=2.5 if tin(17apr1935,1jul1940)
																
																
																
																replace annual_coupon_cash_zurich=4.5 if tin(17apr1935,1jul1940)
																replace annual_coupon_noncash_zurich=2.5 if tin(17apr1935,1jul1940)
											
																* change in July 1936
																replace annual_coupon_cash_zurich=2	if tin(6jul1936,1jul1940)
																replace annual_coupon_noncash_zurich=5 if tin(6jul1936,1jul1940)
																
																* change in Oct 1936
																replace annual_coupon_cash_zurich=0 if tin(18oct1936,1jul1940)
																replace annual_coupon_noncash_zurich=7 if tin(18oct1936,1jul1940)
															
																* change in Dec 1936
																replace annual_coupon_cash_zurich=2.5 if tin(23dec1936,1jul1940)
																replace annual_coupon_noncash_zurich=4.5 if tin(23dec1936,29jun1937)
																
																* change in June 1937
																replace annual_coupon_noncash_zurich=3 if tin(30jun1937,1jul1940)
 
																* change in June 1938
 																replace annual_coupon_cash_zurich=4 if tin(30jun1938,1jul1940)
																replace annual_coupon_noncash_zurich=1.5 if tin(30jun1938,1jul1940)

																* change in July 1939
																replace annual_coupon_cash_zurich=2.75 if tin(5Jul1939,1jul1940)
																replace annual_coupon_noncash_zurich=2.75 if tin(5Jul1939,1jul1940)
															
															
								
										* merge Dawesmark/RM exchange rate to calculate GBP equivalent of non-cash payment
										
									
												merge 1:1 date using  "$Replicationdirectory/_Work/TEMP/DMRMrate"
												
													drop _merge
												
															 
															
															
											foreach market of global markets{
												gen annual_coupon_`market'=7 																					if tin(1jan1930,16apr1935)
												replace annual_coupon_`market'=annual_coupon_cash_`market'+annual_coupon_noncash_`market'*(RateRegisterRM/100)  if tin(17apr1935,1jul1940)
											}
										 
										
										preserve 
											gen dayofmonth = day(date)
											keep date	annual_coupon_london	annual_coupon_paris	annual_coupon_amsterdam	annual_coupon_zurich	P_london_GBP_GBP	P_paris_GBP_GBP	P_amsterdam_GBP_GBP	P_zurich_GBP_GBP	month year	dayofmonth
											order date	annual_coupon_london	annual_coupon_paris	annual_coupon_amsterdam	annual_coupon_zurich	P_london_GBP_GBP	P_paris_GBP_GBP	P_amsterdam_GBP_GBP	P_zurich_GBP_GBP	month year	dayofmonth
											export excel using "$Replicationdirectory/_Work/TEMP/COUPONCHANGES_TABLE_INCLOTHERCURRENCY.xlsx", firstrow(variables) replace

										restore 
		
		
										
										}
										
										
										
		*** add YTMs	(run Matlab script after error is returned when first executing script)								
		{														
														preserve 
															clear 
															
															import delimited "$Replicationdirectory/_Data/Yield to maturity/YTM_allmarkets.csv",      varnames(1) case(preserve)
															destring YTM*, replace force
															generate date=date(Year,"DMY") 
															format date %d
															drop Year
															
															save "$Replicationdirectory/_Work/TEMP/ytm_allmarkets", replace 
															
														restore 
														
														 merge 1:1 date using  "$Replicationdirectory/_Work/TEMP/ytm_allmarkets"
														 
														 drop _merge  
  
														
												foreach market of global markets{
															rename YTM_PD_`market' ytm_`market'
															label var ytm_`market' "YTM - `market' (including partial default on coupon in ytm calculation)" 
															
															*rescale
															replace  ytm_`market'= ytm_`market'*100
															
														 
													}
													
			}
										
 		*** add Lesmond    measure of liquidity
 			
			foreach market of global markets{
					 
					preserve		
							* for comparable measures, focus on London 5-day tranding week:
 							drop if tradingday_london==.
							
							gen P_london_LCU=P_london_GBP_GBP
							sort day_in_sample
							
							gen d_P_`market'_LCU=P_`market'_LCU-P_`market'_LCU[_n-1]
							
							gen nonzero_day_`market'=1 if d_P_`market'_LCU!=0 & d_P_`market'_LCU!=.
						 
							replace nonzero_day_`market'=0 if nonzero_day_`market'==.
							
											
							* 21-day backward looking average
							gen liquidity_`market'=100*(nonzero_day_`market'[_n-1]+nonzero_day_`market'[_n-2]+nonzero_day_`market'[_n-3]+nonzero_day_`market'[_n-4]+nonzero_day_`market'[_n-5]+nonzero_day_`market'[_n-6]+nonzero_day_`market'[_n-7]+nonzero_day_`market'[_n-8]+nonzero_day_`market'[_n-9]+nonzero_day_`market'[_n-10]+nonzero_day_`market'[_n-11]+nonzero_day_`market'[_n-12]+nonzero_day_`market'[_n-13]+nonzero_day_`market'[_n-14]+nonzero_day_`market'[_n-15]+nonzero_day_`market'[_n-16]+nonzero_day_`market'[_n-17]+nonzero_day_`market'[_n-18]+nonzero_day_`market'[_n-19]+nonzero_day_`market'[_n-20]+nonzero_day_`market'[_n-21])/21
							
							gen ln_liquidity_`market'=log(1+ liquidity_`market')
							
							gen rel_liquidity_`market'=liquidity_`market'-liquidity_london
							
							
 							tsset date
							tsegen liquitdity_60ma_`market'= rowmean(liquidity_`market' L(1/60).liquidity_`market')
							 
							keep liquidity_`market' liquitdity_60ma_`market' date ln_liquidity_* rel_liquidity_*
							
							save "$Replicationdirectory/_Work/TEMP/liquidity_`market'" , replace 
					restore		
					 
					merge 1:1  date	using	"$Replicationdirectory/_Work/TEMP/liquidity_`market'", 
					drop _merge

				}
				
			
			
			
 		
		
		*** create variable with "last available value" extrapolation			
												foreach market of global markets{
															 
															*  YTM 
															gen ytm_`market'_lastavail= ytm_`market'
															replace  ytm_`market'_lastavail= ytm_`market'_lastavail[_n-1]  if ytm_`market'  >=. 
															
															* Price 
															gen P_`market'_GBP_GBP_lastavail= P_`market'_GBP_GBP 
															replace  P_`market'_GBP_GBP_lastavail= P_`market'_GBP_GBP_lastavail[_n-1]  if P_`market'_GBP_GBP  >=. 
															 
											
													}
		
		
		save "$Replicationdirectory/_Work/TEMP/_data_bonds.dta", replace	
										
										
										
		